package org.lc.platform.base.domain;

import cn.hutool.core.util.ObjUtil;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.io.Serial;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Lc
 */
@Data
@Schema(description = "用户信息")
public class JwtUser implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    @Schema(name = "主键")
    private String userId;

    @Schema(name = "昵称")
    private String nickName;

    @Schema(name = "账号")
    private String username;

    @Schema(name = "密码")
    private String password;

    @Schema(name = "状态")
    private int status;

    @Schema(name = "禁用")
    private boolean forbidden;

    @Schema(name = "是否是超级管理员")
    private boolean superAdmin;

    @Schema(name = "所属平台ID")
    private String clientId;

    @Schema(name = "角色")
    private List<String> roles = new ArrayList<>();

    @Schema(name = "菜单权限")
    private List<String> acls = new ArrayList<>();

    @Schema(name = "接口权限")
    private List<String> apis = new ArrayList<>();

    /**
     * 客户端信息
     */
    @Schema(name = "客户端信息")
    private String clientSign;

    public void addRole(String role) {
        if (ObjUtil.isNull(this.roles)) {
            this.roles = new ArrayList<>();
        }
        if (ObjUtil.isNotNull(role) && !this.roles.contains(role)) {
            this.roles.add(role);
        }
    }

    public void addAcl(String acl) {
        if (ObjUtil.isNull(this.acls)) {
            this.acls = new ArrayList<>();
        }
        if (ObjUtil.isNotNull(acl) && !this.acls.contains(acl)) {
            this.acls.add(acl);
        }
    }

    public void addApi(String api) {
        if (ObjUtil.isNull(this.apis)) {
            this.apis = new ArrayList<>();
        }
        if (ObjUtil.isNotNull(api) && !this.apis.contains(api)) {
            this.apis.add(api);
        }
    }
}
